const { compact } = require("lodash")

// 基类
class HttpException extends Error {
    constructor(msg = '服務器異常', errorCode = 10001, code = 400) {
        super()
        this.msg = msg
        this.errorCode = errorCode
        this.code = 400
    }
}

/** 具体异常类 */
// 参数错误
class ParameterException extends HttpException {
    constructor(msg, errorCode) {
        super()
        this.code = 400;
        this.msg = msg || '参数错误';
        this.errorCode = errorCode || 10000;
    }
}



// sucess
class Success extends HttpException {
    constructor(msg, errorCode) {
        super()
        this.msg = msg || 'ok';
        this.errorCode = errorCode || 0;
        this.code = 201;
    }
}

// 数据不存在
class NotFound extends HttpException{
    constructor(msg, errorCode) {
        super()
        this.msg = msg || '资源未找到';
        this.errorCode = errorCode || 10000;
        this.code = 400;
    }
}
// 用户授权失败
class AuthFailed extends HttpException{
    constructor(msg, errorCode) {
        super()
        this.msg = msg || '授权失败';
        this.errorCode = errorCode || 10000;
        this.code = 401;
    }
}
// 授权失败，禁止访问   token 过期
class Forbbiden extends HttpException{
    constructor(msg, errorCode) {
        super()
        this.msg = msg || '授权已过期，禁止访问';
        this.errorCode = errorCode || 10006;
        this.code = 403;
    }
}

class LikeError extends HttpException{
    constructor(msg, errorCode){
        super()
        this.msg = msg || '你已经点赞过了';
        this.errorCode = errorCode || 10007;
        this.code = 201;
    }  
}
class DisLikeError extends HttpException{
    constructor(msg, errorCode){
        super()
        this.msg = msg || '你已取消点赞';
        this.errorCode = errorCode || 10007;
        this.code = 203;
    }  
}


module.exports = {
    HttpException,
    ParameterException,
    NotFound,
    AuthFailed,
    Forbbiden,
    LikeError,
    DisLikeError,
    Success
}